package cn.edu.zut.hhr.utils;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class RestResponse<T> implements Serializable {

    public static final int CODE_200 = 200;
    public static final int CODE_500 = 500;

    private int code = CODE_200;
    private String msg = "";
    private T data = null;

    public static <T> RestResponse<T> success(int code, String msg, T data){
        return new RestResponse<>(code,msg,data);
    }
    public static <T> RestResponse<T> success(String msg,T data){
        return success(CODE_200,msg,data);
    }

    public static <T> RestResponse<T> success(String msg){
        return success(CODE_200,msg,null);
    }

    public static <T> RestResponse<T> success(T data){
        return success(CODE_200,"",data);
    }

    public static <T> RestResponse<T> fail(int code, String msg){
        return new RestResponse<T>(code,msg,null);
    }

    public static <T> RestResponse<T> fail(String msg){
        return fail(CODE_500,msg);
    }

}
